package com.hanhanxiaochong.zhongxiangchuanmei.view.home.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.HotProjectBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.util.glide.GlideImgManager;
import com.hanhanxiaochong.zhongxiangchuanmei.view.home.act.HomeVipActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.List;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/5/2.
 * Desc   : 热门项目adapter
 */

public class HotProjectAdapter extends CommonAdapter<HotProjectBean> {

    public HotProjectAdapter(Context context, int layoutId, List<HotProjectBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, HotProjectBean bean, int position) {
        ImageView pic = holder.getView(R.id.iv_good_pic);
        ImageView ivSelfSupport = holder.getView(R.id.iv_self_support);
        TextView name = holder.getView(R.id.tv_good_name);
        TextView projectFit = holder.getView(R.id.tv_project_fit);
        TextView vipPrice = holder.getView(R.id.tv_vip_price);
        TextView normalPrice = holder.getView(R.id.tv_normal_price);
        ImageView becomeVip = holder.getView(R.id.iv_becom_vip);
        TextView tvAppoint = holder.getView(R.id.tv_appoint_now);
        TextView projectTime = holder.getView(R.id.tv_project_time);
        String user_type = SharedPreferencesUtil.getsInstances(mContext).getLoginInfo().getUser_type();
        becomeVip.setVisibility(!user_type.equals("1") ? View.GONE : View.VISIBLE);
        tvAppoint.setVisibility(!user_type.equals("1") ? View.VISIBLE : View.GONE);

        GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + (bean.getPic().split(",")[0]), R.mipmap.img_error, R.mipmap.img_error, pic);
        ivSelfSupport.setVisibility(bean.getSelf_support().equals("y") ? View.VISIBLE : View.GONE);
        name.setText(bean.getName());
        vipPrice.setText(String.format(ResourcesUtils.getString(R.string.vip_good_price), bean.getPrice_vip()));
        normalPrice.setText(String.format(ResourcesUtils.getString(R.string.normal_good_price), bean.getPrice()));
        projectFit.setText(String.format(ResourcesUtils.getString(R.string.project_fit), ""));
        projectTime.setText(String.format(ResourcesUtils.getString(R.string.project_time), bean.getWhen_long()));
        holder.setOnClickListener(R.id.iv_becom_vip, v -> {
            mContext.startActivity(HomeVipActivity.createIntent(mContext));
        });
        holder.itemView.setOnClickListener(v -> mOnItemClickListener.onItemClick(this, position));
    }
}
